<?php

header('Content-Type: text/html;charset=UTF-8');
$_SESSION['page'] = 'info';

$totalRows = Db::getOneField('COUNT(*)', 'article', 'type=8');
$perPage = Config::get('num_per_page');
$pageNum = isset($_GET['p']) ? intval($_GET['p']) : 1;
if ($pageNum < 1) {
    $pageNum = 1;
}

$newspaging = Tpl::page($totalRows, $perPage, 'info?p=');
$rows = Db::getRows('*', 'article where type = 8 order by id desc limit ' . ($pageNum - 1) * $perPage . ',' . $perPage);
$newslist = '';
foreach ($rows as $value => $row) {
    $id = $row['id'];
    $avatar = $row['img'];
    $title = $row['title'];
    $posteddate = $row['posteddate'];
    $newslist.= '<tr>
                  <td class="check">'.++$value.'</td>
                  <td><img width="69px" height="37px" alt="product image" src="../upload/'.$avatar.'"></td>
                  <td class="item_name"><a title="" href="www.hocquocte.com/entry?id='.$id.'">'.$title.'</a></td>
                  <td class="status">'.$posteddate.'</td>
                  <td class="tool">
                      <a onclick="return confirm(\'Bạn có chắc chắn muốn xóa?\')" href="infoDel?id='.$id.'&p='.$pageNum.'" class="btPink">
                          <span>
                              <span>Xóa</span>
                          </span>
                      </a>
                      <a href="infoEdit?id='.$id.'" class="btBlue">
                          <span>
                              <span>Sửa</span>
                          </span>
                      </a>
                  </td>
                </tr>';
}
$newslist = $newslist == '' ? '<tr><td colspan="5">chưa có dữ liệu</td></tr>' : $newslist;
?>

